package com.leyou.controller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import com.leyou.server.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SpecController {
    @Autowired
    private SpecService specService;
    /**
     * 查询规格组信息
     * GET /spec/groups/of/category?id=76
     */
    @GetMapping("/spec/groups/of/category")
    public ResponseEntity<List<SpecGroup>>findSpecGroup(
            @RequestParam("id") Long id
    ){
        List<SpecGroup> specGroup = specService.findSpecGroup(id);
        return ResponseEntity.ok(specGroup);
    }
    /**
     * 查询规格参数
     */
    @GetMapping("/spec/params")
    public ResponseEntity<List<SpecParam>> findSpecParam(
            @RequestParam(value = "gid" ,required = false) Long gid,
            @RequestParam(value = "cid",required = false) Long cid,
            @RequestParam(value = "searching",required = false) Boolean  searching
    ){
        List<SpecParam> specParam = specService.findSpecParam(gid, cid, searching);

        return ResponseEntity.ok(specParam);
    }
    /**
     * 根据分类ID查询规格组（包含组内参数）
     */
    @GetMapping("/spec/of/category")
    public ResponseEntity<List<SpecGroupDTO>> findSpecGroupDTOByCid(@RequestParam("id") Long id){
        List<SpecGroupDTO> specGroupDTOS = specService.findSpecGroupDTOByCid(id);
        return ResponseEntity.ok(specGroupDTOS);
    }
}
